// import { visitLogin } from '@/request/user.js'
export default {
  namespaced: true,
  state() {
    return {
      history: [],
      cookie: '',
      userId: '',
      profile: {},
      redirect:'',
      user:null
    }
  },
  mutations: {
    // 添加历史
    addHistory(state, item) {
      const find = state.history.findIndex(v => v === item)
      if (find > -1) {
        state.history.splice(find, 1)
      }
      state.history.unshift(item)
    },
    // 删除历史
    delHistory(state, item) {
      const find = state.history.findIndex(v => v === item)
      if (find > -1) {
        state.history.splice(find, 1)
      }
    },
    // 清空历史
    clearHistory(state) {
      if (state.history.length) {
        state.history = []
      }
    },
    // 记录用户信息
    saveUserInfo(state,payload){
      state.user = payload
    },
    setCookie(state, value) {
      state.cookie = value
    },
    setId(state, id) {
      state.userId = id
    },
    setProfile(state, profile) {
      state.profile = profile
    },
    logout(state) {
      state.cookie = ''
      state.userId = ''
      state.profile = {},
      state.user = null
    },
    setRedirect(state,redirect){
      state.redirect = redirect
      console.log(state.redirect);
    }
  },
  actions: {
    // async visitLogin({commit}){
    //    const res = await visitLogin()
    //    commit('saveUserInfo',res)
    //  }
  },
  getters: {

  }
}
